// *** LICENSE HEADER ***
// Filename: ./nodegraph.h
// This file is part of Nodewarz 0.1
// Nodewarz is a 3d OpenGL strategy game
// Copyright (C) 2007 CZestmyr
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// *** END LICENSE HEADER ***
#ifndef NODEWARS_NODEGRAPH_H
#define NODEWARS_NODEGRAPH_H

#include <SDL.h>
#include <GL/gl.h>
#include <deque>
#include "node.h"
#include "connnode.h"
#include "player.h"
#include "lightmanager.h"
#include "imagefunctions.h"
#include "resource.h"

class node;
class lightManager;
class player;

//Class that stores all the nodes for one player
class nodeGraph {
    public:
        nodeGraph(player* newParent);
        ~nodeGraph();

        //Get the player
        player* GetParent();
        //Set/Get the light manager for the game
        void SetLightManager(lightManager* newManager);
        lightManager* GetLightManager();

        //Add a new node
        node* AddNode(float posX, float posY);
        //Remove a node
        void RemoveNode(node* toRemove);
        //Get node that is closest to the given point
        node* GetClosestNode(float posX, float posY);

        //Reset the node growth helper data in order to be able to distribute resources
        void ResetGrowthData();
        //Increase all the nodes' sizes
        void Grow();

        //Reset all the lights of all the nodes (asymptotically innefective and thus not used)
        void ResetLights();

        //Draw the nodes in this nodegraph
        void Draw(bool showBoundaries, bool friendly, bool showEnergies);

        //Find out, whether the graph contains any nodes or not
        bool IsEmpty();

        //Load the global nodegraph textures
        static void LoadTextures();
        //Unload the global nodegraph textures
        static void UnloadTextures();
    private:
        //Node linked-list pointer
        node* first;

        player* parent;
        lightManager* theLightManager;

        //Flag to mark, whether the graph was used already or not
        bool yetUnused;

        //Circle texture used for showing node boundaries
        static GLuint circleTexture;
};

#endif
